#include<iostream>
using namespace std;

void reverseS(string &s){
    int n=s.size()/2;
    for(int i=0;i<n;++i)  swap(s[i],s[s.size()-i-1]);
}

int findN(const string& l, const string& s) {
    if (s.size() > l.size()) return 0;//如果短字符串长于长字符串，直接返回0
    int res = 0;
    int n = l.size() - s.size();
    auto same = [s, l](int begin) {//判断两个字符串是否相等
        for (int i = 0; i < s.size(); i++) if (l[begin++] != s[i]) return false;
        return true;
    };
    for (int i = 0; i <= n; ++i) {
        if (same(i)) ++res;
    }
    return res;
}

class matrix {
private:
    int rows = 0;
    int colmns = 0;
    int* ma = nullptr;
public:
    matrix() {}
    matrix(int m, int n);
    matrix(const matrix&);
    ~matrix() { delete[] ma; }
    void transpose();
    void print()const;
};

matrix::matrix(int m, int n) :rows(m), colmns(n) {
    ma = new int[m * n];
    for (int i = 0; i < m * n; i++) ma[i] = rand() % 100;
}

void matrix::transpose() {
    int* temp = new int[rows * colmns];
    for (int i = 0; i < rows; ++i)
        for (int j = 0; j < colmns; ++j) {
            temp[rows * j + i] = ma[i * colmns + j];
        }
    int* p = ma;
    ma = temp;
    delete[]p;
    swap(colmns, rows);
}

void matrix::print()const {
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < colmns; ++j)
        {
            cout.width(4);
            cout << ma[i * colmns + j];
        }
        cout << endl;
    }
}

matrix::matrix(const matrix& m) :rows(m.rows), colmns(m.colmns) {
    int nums = rows * colmns;
    ma = new int[nums];
    for (int i = 0; i < nums; i++)ma[i] = m.ma[i];
}

int main(void) {
    cout<<"int: "<<sizeof(int);
    cout<<"  double: "<<sizeof(double);
    cout<<"  float: "<<sizeof(float);
    cout<<"  char: "<<sizeof(char)<<endl;
    cout<<"  long: "<<sizeof(long);
    cout<<"  long long: "<<sizeof(long long);
    cout<<"  short: "<<sizeof(short);
    cout<<"  bool: "<<sizeof(bool)<<endl;

    matrix test(4, 3);
    test.print();
    test.transpose();
    cout << endl;
    test.print();
    cout<<endl;
  
  string s("hello world hehe hello he");
  cout<<s<<endl;
  cout<<"s含有";

  cout<<findN(s,"he")<<"个 he 字符串"<<endl;

  string s2("Let,s study c++");
  cout<<s2<<endl;
  reverseS(s2);//测试反转函数
  cout<<s2<<endl<<endl;
    return 0;
}
